package com.waimai1.waimai.service.impl;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.waimai1.waimai.common.BaseContext;
import com.waimai1.waimai.common.ExcelListener;
import com.waimai1.waimai.dao.ChoujiangDao;
import com.waimai1.waimai.entity.Choujiang;
import com.waimai1.waimai.entity.ChoujiangWhite;
import com.waimai1.waimai.service.ChoujiangService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.util.*;

/**
 * (Choujiang)表服务实现类
 *
 * @author makejava
 * @since 2023-11-14 11:00:21
 */
@Service("choujiangService")
public class ChoujiangServiceImpl extends ServiceImpl<ChoujiangDao, Choujiang> implements ChoujiangService {
    @Autowired
    private RedisTemplate redisTemplate;
//    获取当前抽奖活动
    public Choujiang getCurrentChoujiang(){
        LambdaQueryWrapper<Choujiang> choujiangLambdaQueryWrapper=new LambdaQueryWrapper<>();
        Date now=new Date();
        choujiangLambdaQueryWrapper.eq(Choujiang::getAcid, BaseContext.getAcid())
                .lt(Choujiang::getStartTime,now)
                .gt(Choujiang::getEndTime,now);
        Choujiang choujiangRes=this.getOne(choujiangLambdaQueryWrapper,false);
        return choujiangRes;
    }
    public  void saveExcel(List<ChoujiangWhite> whiteList) {
        Set phones=new HashSet();
        for(ChoujiangWhite white:whiteList){
            phones.add(white.getPhone());
        }
        redisTemplate.opsForSet().add(BaseContext.getAcid()+":choujiangWhite",phones.toArray());
    }
    public void clearExcelRedis(){
        redisTemplate.delete(BaseContext.getAcid()+":choujiangWhite");
    }
}

